package com.skycong.hello77.activity.gridview;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.SimpleAdapter;
import com.skycong.hello77.R;
import com.skycong.hello77.activity.login.Login1;
import com.skycong.hello77.activity.personhome.PersonHomeActivity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class GridViewActivity extends Activity implements AdapterView.OnItemClickListener {
    private GridView gridView;
    private SimpleAdapter sim_adapter;
    private List<Map<String,Object>> dataList;
    private int[] pic={R.mipmap.dingdan_empty_icon,
            R.mipmap.close_btn,
            R.mipmap.disclosurearrow_new,
            R.mipmap.dingdan_empty_icon,
            R.mipmap.basic_icon_paixu,
            R.mipmap.close_btn};
    private String[] text = {"登录",
            "个人主页",
            "产品列表页",
            "详情页",
            "邮箱自动补全",
            "AndroidDemo"};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        dataList = new ArrayList<Map<String,Object>>();
        gridView = (GridView) findViewById(R.id.grid_view);
        sim_adapter = new SimpleAdapter(this,getData(),R.layout.grid_item,new String[]{"pic","text"},new int[]{R.id.pic,R.id.text});

        gridView.setAdapter(sim_adapter);
        gridView.setOnItemClickListener(this);
    }

    private List<Map<String,Object>> getData(){

        for(int i=0;i<text.length;i++){
            Map<String,Object> map = new HashMap();
            map.put("pic",pic[i]);
            map.put("text",text[i]);
            dataList.add(map);
        }

        return dataList;
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
       switch (text[position]){
           case "登录":{
               Intent intent = new Intent(GridViewActivity.this, Login1.class);
               GridViewActivity.this.startActivity(intent);
               break;
           }
           case  "个人主页":{
               Intent intent = new Intent(GridViewActivity.this,PersonHomeActivity.class);
               GridViewActivity.this.startActivity(intent);
               break;
           }

       }

    }
}
